$(function(){
	$("#themeList img:gt(5)").lazyload({
		placeholder: "/dorimeme/app/webroot/img/global/loading-spiral.gif",
		effect : "fadeIn",
		container : "#themeList"
	});
})



$(document).ready(function(){
	var $settingBar = new SettingBar("#settingBar");
});

function SettingBar(barSelStr){
	var _this = this;
	this.$settingBar = $(barSelStr);
	this.$container = this.$settingBar.parent();
	this.$items = $("a", this.$settingBar);
	this.$items.removeClass("current");
	this.$settingMenu = this.$container.children(".settingMenu");
	this.$items.each(function(index){
		$(this).click(function(){
			// when item is clicked already
			if($(this).attr("class") == "current"){
				// remove current class
				$(this).removeClass("current");
				
				// hide the div according to index
				_this.$settingMenu.eq(index).fadeOut('fast');
			}else{
				// when this is a new item clicked
				
				// remove the current and set it to this item
				var $before = $(_this.$items.filter(".current"));
				$before.removeClass("current");
				
				
				// disable the before menu item
				var beforeIndex = _this.$items.index($before);
				_this.$settingMenu.eq(beforeIndex).fadeOut(0,function(){
						
					// add the current to new item
					
					// show the new menu
					_this.$settingMenu.eq(index).fadeIn(300).trigger("scroll");
					
				});
				$(this).addClass("current");
				
			}
			return false;
		});

		
//		$(this).blur(function(){
//			// remove current class
//				$(this).removeClass("current");
//				
//			// hide the div according to index
//			_this.$settingMenu.eq(index).hide('fast');
//		});
	});
	
	// set click event to each theme
	$("#themeList li").click(function(){
		// get theme template's url
		var url = "";
		$body = $("#themeWrap");
		$body.empty();
		$.get('/dorimeme/blogs/template/red',function(data){
			
			$("#themeWrap").html(data);
			
			var $css = $("head link");
			$css.last().attr("href", "/dorimeme/css/../theme/red/css/default.css");			
		});
		//$body.load("/dorimeme/blogs/customize/red");
		
		//$("#container #content").empty().load();	
		
	});
	
	
	
}
